package com.tongji.housediy.view
{
	import com.tongji.housediy.events.commonEvent.ChangeData3D;
	import com.tongji.housediy.events.commonEvent.SetCompStateEvent;
	import com.tongji.housediy.model.CompEnableStateModel;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.binding.utils.BindingUtils;
	
	import org.robotlegs.mvcs.Mediator;

	/**
	 * 
	 * @author xuxunjia
	 * 
	 */	
	public class DirectCompMediator extends Mediator
	{
		[Inject]
		public var view:DirectComp;
		
		[Inject]
		public var model:CompEnableStateModel;
		
		override public function onRegister():void
		{
			BindingUtils.bindProperty(view.frontBtn, "enabled", model, "isMove3DBtnEnable");
			BindingUtils.bindProperty(view.backBtn, "enabled", model, "isMove3DBtnEnable");
			BindingUtils.bindProperty(view.moveUpBtn, "enabled", model, "isMove3DBtnEnable");
			BindingUtils.bindProperty(view.moveDownBtn, "enabled", model, "isMove3DBtnEnable");
			BindingUtils.bindProperty(view.moveRightBtn, "enabled", model, "isMove3DBtnEnable");
			BindingUtils.bindProperty(view.moveLeftBtn, "enabled", model, "isMove3DBtnEnable");
			BindingUtils.bindProperty(view.cameraDownBtn, "enabled", model, "isMove3DBtnEnable");
			BindingUtils.bindProperty(view.cameraUpBtn, "enabled", model, "isMove3DBtnEnable");
			
			view.frontBtn.addEventListener(MouseEvent.CLICK, frontBtnClickHandler);
			view.backBtn.addEventListener(MouseEvent.CLICK, backBtnClickHandler);
			view.moveCenterBtn.addEventListener(MouseEvent.CLICK, moveCenterBtnClickHandler);
			view.moveUpBtn.addEventListener(MouseEvent.MOUSE_DOWN, moveUpBtnClickHandler);
			view.moveDownBtn.addEventListener(MouseEvent.MOUSE_DOWN, moveDownBtnClickHandler);
			view.moveRightBtn.addEventListener(MouseEvent.MOUSE_DOWN, moveRightBtnClickHandler);
			view.moveLeftBtn.addEventListener(MouseEvent.MOUSE_DOWN, moveLeftBtnClickHandler);
			view.addEventListener(MouseEvent.MOUSE_UP, moveStop);
			view.addEventListener(MouseEvent.MOUSE_OUT, moveStop);
			view.cameraDownBtn.addEventListener(MouseEvent.MOUSE_DOWN,cameraDownBtnClickHandler);
			view.cameraUpBtn.addEventListener(MouseEvent.MOUSE_DOWN,cameraUpBtnClickHandler);
			
			//view.addEventListener(Event.REMOVED_FROM_STAGE, removedFromStageHandler);
			
		}
		
		private function addToStageHandler(event:Event):void
		{
		}
		
		private function frontBtnClickHandler(event:MouseEvent):void
		{
			dispatch(new ChangeData3D(ChangeData3D.ADD_ANGLE));
		}
		
		private function backBtnClickHandler(event:MouseEvent):void
		{
			dispatch(new ChangeData3D(ChangeData3D.SUB_ANGLE));
		}
		
		private function moveUpBtnClickHandler(event:MouseEvent):void
		{
			dispatch(new ChangeData3D(ChangeData3D.MOVE_UP));
		}
		
		private function moveDownBtnClickHandler(event:MouseEvent):void
		{
			dispatch(new ChangeData3D(ChangeData3D.MOVE_DOWN));
		}
		
		private function moveRightBtnClickHandler(event:MouseEvent):void
		{
			dispatch(new ChangeData3D(ChangeData3D.MOVE_RIGHT));
		}
		
		private function moveLeftBtnClickHandler(event:MouseEvent):void
		{
			dispatch(new ChangeData3D(ChangeData3D.MOVE_LEFT));
		}
		
		private function moveStop(event:MouseEvent):void
		{
			dispatch(new ChangeData3D(ChangeData3D.MOVE_STOP));
		}
		
		private function moveCenterBtnClickHandler(event:MouseEvent):void
		{
			// 设置 3D 按钮的 enabled 属性，通过其绑定属性
			dispatch(new SetCompStateEvent(SetCompStateEvent.SET_COMP_NORMAL_STATE));
			
			dispatch(new ChangeData3D(ChangeData3D.MOVE_CENTER));
		}
		
		private function cameraDownBtnClickHandler(event:MouseEvent):void
		{
			dispatch(new ChangeData3D(ChangeData3D.CAMERA_DOWN));
		}
		
		private function cameraUpBtnClickHandler(event:MouseEvent):void
		{
			dispatch(new ChangeData3D(ChangeData3D.CAMERA_UP));
		}
	}
}